<template>
	<view class="all">
		<view class="box">
			<view class="left">
				真实姓名
			</view>
			<view class="right">
				<input type="text" placeholder="请输入你的姓名" v-model="name" />
			</view>
		</view>
		<view class="box">
			<view class="left">
				银行卡号
			</view>
			<view class="right">
				<input type="number" placeholder="请输入你的银行卡号" v-model="banknum" />
			</view>
		</view>
		<view class="box">
			<view class="left">
				银行
			</view>
			<view class="right">
				<input type="text" placeholder="请选择银行" @click="chosebank()" v-model="bank" />
			</view>
		</view>
		<view class="box">
			<view class="left">
				开户行
			</view>
			<view class="right">
				<input type="text" placeholder="请输入开户行" v-model="bankaddress" />
			</view>
		</view>
		<u-picker :show="show" :columns="columns" @confirm="confirm" @cancel="cancel"></u-picker>
		<view class="last" @click="chose()">
			确定
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name: "",
				banknum: "",
				bank: "",
				bankaddress: "",
				show: false,
				columns: [
					['建设银行', '农业银行', '工商银行', '邮政银行', '中国银行', '招商银行', '中信银行', '交通银行']
				],
				id: ""
			};
		},
		onLoad(option) {
			if (option.id) {
				this.id = option.id
				this.getbankdetil()
			}
		},
		methods: {
			chosebank() {
				this.show = true
			},
			cancel() {
				this.show = false
			},
			confirm(e) {
				this.show = false
				this.bank = e.value[0]
			},
			async getbankdetil() {
				const res = await this.$api("/business/user/bank_details", 'post', {
					id: this.id
				}).then((res) => {
					console.log(res);
					this.name = res.data.data.name
					this.banknum = res.data.data.card_number
					this.bank = res.data.data.bank
					this.bankaddress = res.data.data.opening_bank
				})
			},
			chose() {
				this.$api("/business/user/binding_bank", 'post', {
					name: this.name,
					card_number: this.banknum, //6228220576400814319
					bank: this.bank,
					opening_bank: this.bankaddress,
					id: this.id
				}).then((res) => {
					console.log(res);
					if (res.data.code == 1) {
						uni.$u.toast(res.data.msg)
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.all {
		background-color: #f5f5f5;
		padding: 15px;
		min-height: 100vh;

		.box {
			display: flex;
			align-items: center;
			background: #FFFFFF;
			border-radius: 10px;
			margin: 10px 0;
			justify-content: space-between;
			padding: 10px;

			.left {
				width: 30%;
				font-size: 14px;
				font-weight: bold;
				color: #333333;
			}

			.right {
				flex: 1;
				font-size: 14px;
				font-weight: 400;
				color: #999999;

				input {
					font-size: 14px;
					font-weight: 400;
					color: #999999;
				}

			}
		}

		.last {
			position: fixed;
			bottom: 10%;
			text-align: center;
			width: 90%;
			margin: 0 auto;
			padding: 10px 0;
			border-radius: 40px;
			background-color: #FB774B;
			font-size: 16px;
			font-weight: bold;
			color: #FFFFFF;
		}
	}
</style>